//
//  AY_ReadTopBar.m
//  AiYue
//
//  Created by mac on 2023/10/19.
//

#import "AY_ReadTopBar.h"

@interface AY_ReadTopBar ()

@end

@implementation AY_ReadTopBar

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = COLOR([AYMMKV getStringForKey:ReadToolBackColor defaultValue:@"FEF6E9"]);
        [self addSubview:self.backBtn];
        [self addSubview:self.addBookSelfBtn];
    }
    return self;
}

- (void)click:(UIButton *)btn {
    if (btn == self.backBtn) {
        if ([self.delegate respondsToSelector:@selector(backAction)]) {
            [self.delegate backAction];
        }
    }else if (btn == self.addBookSelfBtn) {
        if ([self.delegate respondsToSelector:@selector(addBookSelfAction:)]) {
            [self.delegate addBookSelfAction:btn];
        }
    }
}

- (UIButton *)backBtn {
    if (!_backBtn) {
        UIButton *backBtn = [AYTool createButtonWithFrame:CGRectMake(0, [UIView statusBar], YNUM(40), [UIView navigationBar]) andTitle:nil andFont:nil andTitleColor:nil andBg:nil andImage:[AYTool isNight] ? YImage(@"AY_nav_pop_w") : YImage(@"AY_nav_pop") andBgImage:nil andTarget:self andAction:@selector(click:) andRadius:0 andAddSubView:self];
        _backBtn = backBtn;
    }
    return _backBtn;
}

- (UIButton *)addBookSelfBtn {
    if (!_addBookSelfBtn) {
        UIButton *addBookSelfBtn = [AYTool createButtonWithFrame:CGRectMake(SCREEN_W - YNUM(120), [UIView statusBar], YNUM(120), [UIView navigationBar]) andTitle:@" 加入书架" andFont:YFont(14) andTitleColor:COLOR([AYMMKV getStringForKey:ReadTitleColor defaultValue:@"422D10"]) andBg:nil andImage:[AYTool isNight] ? YImage(@"AY_add_bookself_night") : YImage(@"AY_add_bookself") andBgImage:nil andTarget:self andAction:@selector(click:) andRadius:0 andAddSubView:self];
        _addBookSelfBtn = addBookSelfBtn;
    }
    return _addBookSelfBtn;
}
@end
